jquery: change the value of `select1` onchange of `select2` IF $('#select2').val() < $('#select1').v
Posted
by Syom
on Stack Overflow
See other posts from Stack Overflow
or by Syom
Published on 2010-05-29T16:42:08Z
Indexed on
2010/05/29
16:52 UTC
Read the original article
Hit count: 206
jQuery
i've asked the first question about selects here, i thought, that when i resieve an answer, i would solve and the second part of my problem, but there was a short way to solve first problem, so i have to ask a question again, about second part:
i have two selects
<select id="select1">
<option value="1">1day</option>
<option value="2">2day</option>
<option value="3">3day</option>
</select>
<select id="select2">
<option value="1">1day</option>
<option value="2">2day</option>
<option value="3">3day</option>
</select>
and i need to change the value of select1
onchange of select2
,
if $('#select2').val() < $('#select1').val();
i try to write the following function
$("#select2").bind('change',function() {
if($('#select2').val() < $('#select1').val())
{
$("#select1").val($(this).val());
}
});
but it doesn't eork, becouse on the moment of change, when i call the function, it doesn't change it's value yet. so, what can i do?
Thakns
© Stack Overflow or respective owner